import { ResouceConst } from "../../../../component/gconst/ResouceConst";
import { ImagesConst } from "../../../resource/ImagesConst";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { GBox } from "../../../../../com/mui/containers/GBox";
import { GBoxDirection } from "../../../../../com/mui/containers/globalVariable/GBoxDirection";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ResFileConst } from "../../../resource/ResFileConst";
import { DailyCompRewardInfo } from "../../../resource/info/DailyCompRewardInfo";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { Language } from "../../../../../extend/language/Language";
import { ObjectPool } from "../../../../../com/gengine/utils/pools/ObjectPool";
import { DegreeRewardIndexItem } from "./DegreeRewardIndexItem";
import { ScaleBitmap } from "../../../../../com/mui/display/ScaleBitmap";
type int = number;
//class DegreeRwardItem
    
    export  class DegreeRwardItem /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.initUI();
            return;
        }

        protected initUI(): void
        {
            this._width = 140;
            this._height = 80;
            this._bg = ResouceConst.getScaleBitmap(ImagesConst.DisabledBg);
            this._bg.width = this._width;
            this._bg.height = this._height;
            addChild(this._bg);
            graphics.clear();
            graphics.beginFill(0, 0);
            graphics.drawRect(0, 0, this.width, this.height);
            graphics.endFill();
            this._infoTxt = new Object /* flash.text.TextField */();
            this._infoTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._infoTxt.width = this.width;
            this._infoTxt.height = 20;
            this._infoTxt.mouseEnabled = false;
            this._infoTxt.x = 5;
            this._infoTxt.y = 2;
            this._infoTxt.filters = [FilterConst.nameGlowFilter];
            addChild(this._infoTxt);
            this._countTxt = new Object /* flash.text.TextField */();
            this._countTxt.defaultTextFormat = new GTextFormat(FontUtil.EmbedNumberName, 20, 65280, true);
            this._countTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._countTxt.width = this.width;
            this._countTxt.height = 20;
            this._countTxt.mouseEnabled = false;
            this._countTxt.x = 42;
            this._countTxt.y = -2;
            this._countTxt.textColor = 65280;
            this._countTxt.embedFonts = true;
            this._countTxt.filters = [FilterConst.glowFilter];
            addChild(this._countTxt);
            this._expTxt = new Object /* flash.text.TextField */();
            this._expTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._expTxt.width = this.width;
            this._expTxt.height = 20;
            this._expTxt.mouseEnabled = false;
            this._expTxt.x = this._infoTxt.x;
            this._expTxt.y = this._infoTxt.y + 17;
            this._expTxt.textColor = 65280;
            addChild(this._expTxt);
            this._goldTxt = new Object /* flash.text.TextField */();
            this._goldTxt.defaultTextFormat = new GTextFormat(FontUtil.EmbedNumberName, 20, 16776960, true);
            this._goldTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._goldTxt.width = this.width;
            this._goldTxt.height = 20;
            this._goldTxt.mouseEnabled = false;
            this._goldTxt.x = 90;
            this._goldTxt.y = this._expTxt.y - 2;
            this._goldTxt.textColor = 16776960;
            this._goldTxt.embedFonts = true;
            this._goldTxt.filters = [FilterConst.glowFilter];
            addChild(this._goldTxt);
            this._goldBmp = GlobalClass.getBitmap(ImagesConst.Yuanbao_bind);
            this._goldBmp.y = this._goldTxt.y + 3;
            addChild(this._goldBmp);
            this._itemBox = new GBox();
            this._itemBox.direction = GBoxDirection.HORIZONTAL;
            this._itemBox.horizontalGap = 2;
            this._itemBox.x = this._infoTxt.x;
            this._itemBox.y = 38;
            addChild(this._itemBox);
            this._endBmp = new Object /* flash.display.Bitmap */();
            this._endBmp.y = this._infoTxt.y;
            this._endBmp.x = 92;
            LoaderHelp.addResCallBack(ResFileConst.daily, this.onDailyResLoadedHandler);
            return;
        }

        /* internal  */onDailyResLoadedHandler(): void
        {
            this._endBmp.bitmapData = GlobalClass.getBitmapData(ImagesConst.DailyEndIcon);
            return;
        }

        public get info(): DailyCompRewardInfo
        {
            return this._info;
        }

        public updateData(arg1: DailyCompRewardInfo): void
        {
            var loc3=0;
            var loc4=0;
            var loc5=null;
            var loc6=null;
            this._info = arg1;
            this._infoTxt.htmlText = HTMLUtil.addColor(Language.getStringByParam(20933, HTMLUtil.addColor(this.space, "#00ff00")) + "：", "#ffff00");
            this._countTxt.text = arg1.index + "";
            var loc1=arg1.getRewardByLevel();
            this._expTxt.text = Language.getString(20934) + "+" + loc1[1];
            this._goldTxt.text = "+" + loc1[2];
            this._goldBmp.x = this._goldTxt.x + this._goldTxt.textWidth + 4;
            var loc2=arg1.itemRewards;
            if (loc2.length > 0) 
            {
                loc4 = loc2.length;
                while (loc3 < loc4) 
                {
                    loc5 = loc2[loc3];
                    (loc6 = ObjectPool.getObject(DegreeRewardIndexItem)).updateData(loc5[1], loc5[2]);
                    this._itemBox.addChild(loc6);
                    ++loc3;
                }
                this._itemBox.layChildChanged = true;
                this._itemBox.invalidate();
            }
            return;
        }

        public filterColor(arg1: int=0): void
        {
            this._expTxt.textColor = 65280;
            this._goldTxt.textColor = 16776960;
            this._infoTxt.htmlText = HTMLUtil.addColor(Language.getStringByParam(20933, HTMLUtil.addColor(this.space, "#00ff00")), "#ffff00");
            if (arg1 != 1) 
            {
                if (arg1 != 2) 
                {
                    if (contains(this._endBmp)) 
                    {
                        removeChild(this._endBmp);
                    }
                }
                else if (!contains(this._endBmp)) 
                {
                    addChild(this._endBmp);
                }
            }
            else if (contains(this._endBmp)) 
            {
                removeChild(this._endBmp);
            }
            return;
        }

        public onGetRewardRes(): void
        {
            var loc1=0;
            var loc3=null;
            var loc2=this._itemBox.numChildren;
            while (loc1 < loc2) 
            {
                loc3 = this._itemBox.getChildAt(loc1) as DegreeRewardIndexItem;
                loc3.flyToPack();
                ++loc1;
            }
            return;
        }

        public dispose(): void
        {
            var loc1=null;
            this._info = null;
            while (this._itemBox.numChildren > 0) 
            {
                loc1 = this._itemBox.removeChildAt(0) as DegreeRewardIndexItem;
                loc1.dispose();
                ObjectPool.disposeObject(loc1, DegreeRewardIndexItem);
            }
            return;
        }

        public /* override */ get height(): number
        {
            return this._height;
        }

        public /* override */ get width(): number
        {
            return this._width;
        }

        /* internal */ /* const */space: string="     ";

        /* internal */ /* var */_info: DailyCompRewardInfo;

        /* internal */ /* var */_bg: ScaleBitmap;

        /* internal */ /* var */_infoTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_countTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_endBmp: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_expTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_goldTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_goldBmp: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_itemBox: GBox;

        /* internal */ /* var */_width: int;

        /* internal */ /* var */_height: int;
    }
